package com.guragura.widget;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.ClickListener;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.guragura.Guragura;
import com.guragura.screens.MainMenuScreen;
import com.guragura.util.Constants;
import com.guragura.util.GuraGameData;

public class HighScorePanel extends Dialog {
	
	public int highscore;
	public int lastHighScore;
	public Guragura guragura;

	public Button background;
	public Image newHighScore;
	public Image bintang;
	int xL;

	public HighScorePanel(float width, float height, Guragura guragura) {
		super(width, height);
		this.guragura = guragura;
		// TODO Auto-generated constructor stub

		background = new Button(
				guragura.atlasInterface
						.findRegion(Constants.NEW_HIGHSCORE_SCREEN));
		bintang = new Image(guragura.atlasInterface.findRegion(
				Constants.BINTANG_HIGHSCORE, 3));
		background.setClickListener(new ClickListener() {

			@Override
			public void click(Actor arg0, float arg1, float arg2) {
				// TODO Auto-generated method stub
				((MainMenuScreen) getGura().mainMenuScreen).hideScorePanel();

			}
		});
		bintang.x = 30;
		bintang.y = 480 / 2 - 30;

		addActor(background);
		addActor(bintang);
	}

	public void setScore(int newhs, int lastscore) {
		this.highscore = newhs;
		this.lastHighScore = lastscore;
		

		xL = (320 - String.valueOf(lastHighScore).length() * 26) / 2;
		System.out.println(xL);
		if (xL < 80) {
			xL = 80;
		}
	}

	@Override
	public void draw(SpriteBatch batch, float parentAlpha) {
		// TODO Auto-generated method stub
		super.draw(batch, parentAlpha);
		guragura.guraFont.drawHS(this.highscore + "", (int) (bintang.x
				+ bintang.width / 2 + 35), 480 / 2);
		// guragura.guraFont.drawHS(this.lastHighScore+"", (100), 480 / 4 -10 );
		// this.lastHighScore = 2133123;
		// xL = ( 320 - String.valueOf(lastHighScore).length() * 26)/2;
		// System.out.println(xL);
		// if (xL<80){
		// xL = 80;
		// }
		guragura.guraFont.drawHS(this.lastHighScore + "", xL, 480 / 4 - 10);

	}

	public Guragura getGura() {
		return guragura;
	}

	public HighScorePanel getSelf() {
		return this;
	}

}
